package com.sxfq.loansupermarket.backsystem.modular.theTest.controller;

import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.common.exception.BizExceptionEnum;
import com.sxfq.loansupermarket.backsystem.common.exception.BussinessException;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.ToolUtil;
import com.sxfq.loansupermarket.backsystem.modular.theTest.entity.TheTestInfo;
import com.sxfq.loansupermarket.backsystem.modular.theTest.service.IInTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 进入考试入口
 *
 * @author py
 * @Date 2018年2月4日23:05:54
 */
@Controller
@RequestMapping("/inTest")
public class InTestController extends BaseController {

    @Autowired
    IInTestService iInTestService;
    /**
     * 跳转输入考试密码页面
     */
    @RequestMapping(value = "/inTheTest", method = RequestMethod.POST)
    public String inTheTest(Model model) {
        String theTestId = super.getPara("theTestId").trim();
        if (ToolUtil.isEmpty(theTestId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        TheTestInfo theTestInfo= iInTestService.getTheTestInfo(theTestId);
        ShiroKit.setSessionAttr("password", theTestInfo.getPassWord());
        ShiroKit.setSessionAttr("theTestName", theTestInfo.getTheTestName());
        ShiroKit.setSessionAttr("theTestId", theTestId);
        return   REDIRECT+"/inTest/inTheTest";
    }

    @RequestMapping(value = "/inTheTest", method = RequestMethod.GET)
    public String enterThePassword(Model model) {
        String password=ShiroKit.getSessionAttr("password");
        String theTestId=ShiroKit.getSessionAttr("theTestId");
        String theTestName=ShiroKit.getSessionAttr("theTestName");
        model.addAttribute("password", password);
        model.addAttribute("theTestName", theTestName);
        model.addAttribute("theTestId", theTestId);
        return   "/theTest/inTest.html";
    }


}
